//
//  ZBNetworkCache.m
//  ZBDay
//
//  Created by xzb on 2018/2/7.
//  Copyright © 2018年 xzb. All rights reserved.
//

#import "ZBNetworkCache.h"
#import "YYCache/YYCache.h"

@interface ZBNetworkCache ()

@property (nonatomic, strong) YYCache *yyCache;

@end
@implementation ZBNetworkCache

+ (instancetype)instance
{
    static dispatch_once_t oncePredicate;
    static id instance;
    dispatch_once(&oncePredicate, ^{
        instance = [[self alloc] init];
    });
    return instance;
};

- (instancetype)init
{
    self = [super init];
    if (self) {
        _yyCache = [[YYCache alloc] initWithName:@"com.zhibin.Network.www"];
    }
    return self;
}

- (void)clearCache
{
    [self.yyCache removeAllObjects];
}

- (void)setData:(NSData *)data forKey:(NSString *)cacheKey
{
    [self.yyCache setObject:data forKey:cacheKey];
}

- (NSData *)dataForKey:(NSString *)cacheKey
{
    return (NSData *) [self.yyCache objectForKey:cacheKey];
}

- (BOOL)containsObjectForKey:(NSString *)key
{
    return [self.yyCache containsObjectForKey:key];
}

@end
